﻿@model GitCandy.Models.CollaborationModel

@{
    ViewBag.Title = string.Format(SR.Shared_TitleFormat, string.Format(SR.Repository_CollaborationTitle, Model.RepositoryName));
}

<h4>@string.Format(SR.Repository_CollaborationTitle, Model.RepositoryName)</h4>

@if (Model != null)
{
    <span>@SR.Shared_Users</span>
    <div id="choose_user"></div>
    <div class="hr"></div>
    <span>@SR.Shared_Teams</span>
    <div id="choose_team"></div>

    <script type="text/javascript">
        var repo = "@Model.RepositoryName";
        var chooser_params = [];
        chooser_params.push(
            {
                data: @Html.Raw(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(Model.Users)),
                controller: "Account",
                container: "#choose_user",
                add_label: "@SR.Shared_Add",
                del_label: "@SR.Shared_Remove",
                add_action: { url: "@Url.Action("ChooseUser", "Repository")", query: function (item) { return { name: repo, user: item, act: "add" }; } },
                del_action: { url: "@Url.Action("ChooseUser", "Repository")", query: function (item) { return { name: repo, user: item, act: "del" }; } },
                action_array: [
                    {
                        key: "AllowRead",
                        on_label: "@SR.Repository_ShortAllowRead",
                        off_label: "@SR.Repository_ShortNonAllowRead",
                        checked: { url: "@Url.Action("ChooseUser", "Repository")", query: function (item) { return { name: repo, user: item, act: "read", value: true }; } },
                        unchecked: { url: "@Url.Action("ChooseUser", "Repository")", query: function (item) { return { name: repo, user: item, act: "read", value: false }; } },
                    },
                    {
                        key: "AllowWrite",
                        on_label: "@SR.Repository_ShortAllowWrite",
                        off_label: "@SR.Repository_ShortNonAllowWrite",
                        checked: { url: "@Url.Action("ChooseUser", "Repository")", query: function (item) { return { name: repo, user: item, act: "write", value: true }; } },
                        unchecked: { url: "@Url.Action("ChooseUser", "Repository")", query: function (item) { return { name: repo, user: item, act: "write", value: false }; } },
                    },
                    {
                        key: "IsOwner",
                        on_label: "@SR.Repository_ShortIsOwner",
                        off_label: "@SR.Repository_ShortNotOwner",
                        checked: { url: "@Url.Action("ChooseUser", "Repository")", query: function (item) { return { name: repo, user: item, act: "owner", value: true }; } },
                        unchecked: { url: "@Url.Action("ChooseUser", "Repository")", query: function (item) { return { name: repo, user: item, act: "owner", value: false }; } },
                    },
                ]
            });

        chooser_params.push(
            {
                data: @Html.Raw(new System.Web.Script.Serialization.JavaScriptSerializer().Serialize(Model.Teams)),
                controller: "Team",
                container: "#choose_team",
                add_label: "@SR.Shared_Add",
                del_label: "@SR.Shared_Remove",
                add_action: { url: "@Url.Action("ChooseTeam", "Repository")", query: function (item) { return { name: repo, team: item, act: "add" }; } },
                del_action: { url: "@Url.Action("ChooseTeam", "Repository")", query: function (item) { return { name: repo, team: item, act: "del" }; } },
                action_array: [
                    {
                        key: "AllowRead",
                        on_label: "@SR.Repository_ShortAllowRead",
                        off_label: "@SR.Repository_ShortNonAllowRead",
                        checked: { url: "@Url.Action("ChooseTeam", "Repository")", query: function (item) { return { name: repo, team: item, act: "read", value: true }; } },
                        unchecked: { url: "@Url.Action("ChooseTeam", "Repository")", query: function (item) { return { name: repo, team: item, act: "read", value: false }; } },
                    },
                    {
                        key: "AllowWrite",
                        on_label: "@SR.Repository_ShortAllowWrite",
                        off_label: "@SR.Repository_ShortNonAllowWrite",
                        checked: { url: "@Url.Action("ChooseTeam", "Repository")", query: function (item) { return { name: repo, team: item, act: "write", value: true }; } },
                        unchecked: { url: "@Url.Action("ChooseTeam", "Repository")", query: function (item) { return { name: repo, team: item, act: "write", value: false }; } },
                    },
                ]
            });
    </script>
}
<div class="form-actions">
    <div class="pull-left">
        @Html.ActionLink(SR.Shared_Back, "Detail", new { Name = Model.RepositoryName }, new { @class = "btn" })
    </div>
</div>
